$(document).ready(function(){
    if($.trim($("#flash").text()).length > 0 ){
        msgbox($("#flash").text());
    }
   
    if ($(".dynamic").length > 0){
        $(".dynamic").jCarouselLite({
            auto: 800,
            speed: 1000,
            vertical: true
        });
    }

    showDate();

});


function showDate(){
    Date.prototype.toString = function(showWeek)
    {
        var myDate= this;
        var str = myDate.toLocaleDateString();
        if (showWeek)
        {
            var Week = ['日','一','二','三','四','五','六'];
            str += ' 星期' + Week[myDate.getDay()];
        }
        return str;
    }

    today = new Date();
    $('#show_date').text(today.toString(true));
}



function addToCart(product_id,tee_size){
    var quantity = $('#item_quantity_on_detail').val();
    var myReg = /\d+/;
    if (!myReg.test(quantity)){
        quantity = '1';
    }

    var url = '/store/add_to_cart/' + product_id + '?quantity=' + quantity + '&tee_size=' + tee_size;
    $('#cart').load(url,function(){
        $('#cart').slideDown('slow');
    });
}



function emptyCart(){
    $.get('/store/empty_cart',function(data){
        alert(data);
    });
}

function msgbox(msg){
    $.growl.settings.displayTimeout = 6000;
    $.growl.settings.noticeTemplate = ''
    + '<div id="msgbox">'
    + '  <h3 id="msg_h3">%title%</h3>'
    + '  <p id="msg_p">%message%</p>'
    + '</div>';

    $.growl("",msg);
}

function bookmark(sURL, sTitle)
{
    try
    {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e)
        {
            alert("加入收藏失败，有劳您手动添加。");
        }
    }
}

function enablePngImages() {
    var imgArr = document.getElementsByTagName("IMG");
    for(i=0; i<imgArr.length; i++){
        if(imgArr[i].src.toLowerCase().lastIndexOf(".png") != -1){
            imgArr[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imgArr[i].src + "', sizingMethod='auto')";
            imgArr[i].src = "spacer.gif";
        }
  
        if(imgArr[i].currentStyle.backgroundImage.lastIndexOf(".png") != -1){
            var img = imgArr[i].currentStyle.backgroundImage.substring(5,imgArr[i].currentStyle.backgroundImage.length-2);
            imgArr[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img+"', sizingMethod='crop')";
            imgArr[i].style.backgroundImage = "url(/images/spacer.gif)";
        }
    }
}

function enableBgPngImages(bgElements){
    for(i=0; i<bgElements.length; i++){
        if(bgElements[i].currentStyle.backgroundImage.lastIndexOf(".png") != -1){
            //alert(bgElements[i]);
            var img = bgElements[i].currentStyle.backgroundImage.substring(5,bgElements[i].currentStyle.backgroundImage.length-2);
            bgElements[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img+"', sizingMethod='crop')";
            bgElements[i].style.backgroundImage = "url(/images/spacer.gif)";
        }
    }
}






